// 枚举类型定义
export enum TodoStatus {
  PENDING = 'pending',
  IN_PROGRESS = 'in_progress',
  COMPLETED = 'completed'
}

export enum TodoPriority {
  LOW = 'low',
  MEDIUM = 'medium',
  HIGH = 'high'
}

export enum UserRole {
  USER = 'user',
  ADMIN = 'admin'
}

// 基础接口定义
export interface TodoBase {
  title: string
  description?: string
  status: TodoStatus
  priority: TodoPriority
  order: number  // 排序字段，数值越小越靠前
  assigned_by_admin?: boolean  // 标识任务是否由管理员分配
}

// 完整的待办事项接口
export interface Todo extends TodoBase {
  id: number
  created_at: string
  updated_at: string
}

// 创建待办事项的请求接口
export interface TodoCreate {
  title: string
  description?: string
  status?: TodoStatus
  priority?: TodoPriority
  order?: number  // 支持设置排序
}

// 更新待办事项的请求接口
export interface TodoUpdate {
  title?: string
  description?: string
  status?: TodoStatus
  priority?: TodoPriority
  order?: number  // 支持更新排序
}

// API 响应接口
export interface ApiResponse<T = any> {
  success: boolean
  message: string
  data?: T
}

export interface TodoListResponse extends ApiResponse<Todo[]> {
  data: Todo[]
  total: number
}

export interface TodoResponse extends ApiResponse<Todo> {
  data: Todo
}

// 统计数据接口
export interface TodoStats {
  total: number
  by_status: {
    pending: number
    in_progress: number
    completed: number
  }
  by_priority: {
    low: number
    medium: number
    high: number
  }
}

// 获取待办事项的查询参数
export interface TodoQueryParams {
  status?: TodoStatus
  priority?: TodoPriority
  limit?: number
}

// 批量排序更新接口
export interface TodoReorderItem {
  id: number
  order: number
}

export interface TodoReorderRequest {
  items: TodoReorderItem[]
}

// 状态和优先级的显示映射
export const STATUS_LABELS = {
  [TodoStatus.PENDING]: '待处理',
  [TodoStatus.IN_PROGRESS]: '进行中',
  [TodoStatus.COMPLETED]: '已完成'
}

export const PRIORITY_LABELS = {
  [TodoPriority.LOW]: '低优先级',
  [TodoPriority.MEDIUM]: '中优先级',
  [TodoPriority.HIGH]: '高优先级'
}

// 状态和优先级的颜色映射
export const STATUS_COLORS = {
  [TodoStatus.PENDING]: 'text-orange-600 bg-orange-100',
  [TodoStatus.IN_PROGRESS]: 'text-blue-600 bg-blue-100',
  [TodoStatus.COMPLETED]: 'text-green-600 bg-green-100'
}

export const PRIORITY_COLORS = {
  [TodoPriority.LOW]: 'text-gray-600 bg-gray-100',
  [TodoPriority.MEDIUM]: 'text-yellow-600 bg-yellow-100',
  [TodoPriority.HIGH]: 'text-red-600 bg-red-100'
}

// 用户相关类型
export interface User {
  id: number
  username: string
  role: UserRole
  created_at: string
  updated_at: string
}

export interface UserListResponse extends ApiResponse<User[]> {
  data: User[]
  total: number
}

// 管理员相关类型
export interface AdminTodoCreate {
  title: string
  description?: string
  status?: TodoStatus
  priority?: TodoPriority
  assigned_to_user_id: number
}

export interface AdminStats {
  total_users: number
  admin_users: number
  regular_users: number
  total_todos: number
}

export interface AdminStatsResponse extends ApiResponse<AdminStats> {
  data: AdminStats
}

// 通知相关类型
export interface Notification {
  id: number
  user_id: number
  title: string
  message: string
  is_read: boolean
  created_at: string
  updated_at: string
}

export interface NotificationListResponse extends ApiResponse<Notification[]> {
  data: Notification[]
  total: number
  unread_count: number
}